﻿Imports ACompany.OrderProcessing.Infrastructure

Public Class Product
    Inherits BusinessBase(Of Product)
    Implements IAggregateRoot
    Implements IEntity

    Private _Name As String
    Private _Price As Decimal
    Private _Stock As Integer

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Public Property Price() As Decimal
        Get
            Return _Price
        End Get
        Set(ByVal value As Decimal)
            _Price = value
        End Set
    End Property

    Public Property Stock() As Integer
        Get
            Return _Stock
        End Get
        Set(ByVal value As Integer)
            _Stock = value
        End Set
    End Property

    Protected Overrides Sub validate()

        If Not Me.Stock >= 0 Then
            Me.BrokenRules.Add(New BrokenRule("Stock", "Stock cannot be a negative number"))
        End If

        If Me.Price < 0 Then
            Me.BrokenRules.Add(New BrokenRule("Price", "Price cannot be a negative number"))
        End If

        If String.IsNullOrEmpty(Me.Name) Then
            Me.BrokenRules.Add(New BrokenRule("Name", "Name is a required value"))
        Else
            If Me.Name.Length > 50 Then
                Me.BrokenRules.Add(New BrokenRule("Name", "Name should be 50 chars or less"))
            End If
        End If

    End Sub
End Class
